﻿// Decompiled with JetBrains decompiler
// Type: MCM.Common.StorageRef`1
// Assembly: MCMv5, Version=5.10.2.0, Culture=neutral, PublicKeyToken=null
// MVID: 7AB326B9-B2B4-41C2-9177-68E944071101
// Assembly location: D:\steam\steamapps\workshop\content\261550\2859238197\bin\Win64_Shipping_Client\MCMv5.dll

using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;

#nullable enable
namespace MCM.Common
{
  public sealed class StorageRef<T> : IRef, INotifyPropertyChanged
  {
    private T? _value;

    public event PropertyChangedEventHandler? PropertyChanged;

    public Type Type { get; }

    public object? Value
    {
      get => (object) this._value;
      set
      {
        if (!(value is T objB) || object.Equals((object) this._value, (object) objB))
          return;
        this._value = objB;
        this.OnPropertyChanged(nameof (Value));
      }
    }

    public StorageRef(T? value)
    {
      this._value = value;
      ref T local1 = ref value;
      Type type;
      if ((object) default (T) == null)
      {
        T obj = local1;
        ref T local2 = ref obj;
        if ((object) obj == null)
        {
          type = (Type) null;
          goto label_4;
        }
        else
          local1 = ref local2;
      }
      type = local1.GetType();
label_4:
      if ((object) type == null)
        type = typeof (T);
      this.Type = type;
    }

    private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
    {
      PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
      if (propertyChanged == null)
        return;
      propertyChanged((object) this, new PropertyChangedEventArgs(propertyName));
    }
  }
}
